package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.CustomerManagement;
import com.woniuxy.entity.dto.CustomerManagementDTO;
import com.woniuxy.mapper.CustomerManagementMapper;
import com.woniuxy.service.CustomerManagementService;
import com.woniuxy.util.PageData;
import com.woniuxy.util.ResponseData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class CustomerManagementServiceImpl implements CustomerManagementService {
    @Resource
    private CustomerManagementMapper customerManagementMapper;
    @Override
    public ResponseData<?> queryCustomer(PageData<CustomerManagementDTO> pageData) {
        // 分页插件开始分页
        PageHelper.startPage(pageData.getPageNum(), pageData.getPageSize());

        List<CustomerManagement> customerManagements = customerManagementMapper.queryCustomer(pageData.getParam());
        // 封装分页类(分页的数据，分页信息(总条数))
        PageInfo pageInfo = new PageInfo(customerManagements);
        return new ResponseData(200, "查询成功", pageInfo);
    }

    @Override
    public ResponseData<?> deleteCustomer(Integer id) {
        customerManagementMapper.deleteCustomer(id);
        return new ResponseData<>().ok();
    }
}
